const { queryAll } = require('../../database/dbUtils')

const moneydata=async (ctx:any)=>{
  let {college,stage,classroom,pageNumber,pageSize}=ctx.request.query
  console.log(college,stage,classroom,pageNumber,pageSize);
  let sql=`select * from scb`
  let res=await queryAll(sql)
  //筛选数据
  let coll:any=[]
  res.forEach((item:any)=>{
    if(college==item.qwstage){
      coll.push(item)
    }
  })
  console.log(coll);
  
  //阶段
  let jie:any=[]
  coll.forEach((item:any)=>{
    if(stage==item.stage){
      jie.push(item)
    }
  })
  //班级
  let ban:any=[]
  jie.forEach((item:any)=>{
    if(classroom==item.banji){
      ban.push(item)
    }
  })
  console.log(ban);
  // 截取数据
  let start=(pageNumber-1)*pageSize
  let end=Number(start+pageSize)
  let jiearr=ban.slice(start,end)
  // console.log(jiearr);
  ctx.status=200
  ctx.body={
    code:"01",
    msg:"获取数据成功",
    result:{res,ban,jiearr}
  }
}

const pay=async (ctx:any)=>{
  let {id,pay,now}=ctx.request.query
  console.log(id,pay,now);
  let n=Number(pay)+Number(now)
  console.log(n);
  
  const sql = 'select * from scb';
  let data: any = await queryAll(sql)
  await queryAll(`update scb set nowmoney='${n}' where id='${id}'`)
  ctx.status=200
  ctx.body={
    code:"01",
    msg:'修改成功',
    // result:res
  }
}
export {
  moneydata,
  pay
}